//
//  NewBuyListCell.swift
//  LeGou
//
//  Created by 刘亿前 on 2022/9/16.
//

import UIKit

class NewBuyListCell: UITableViewCell {
    
    // 图片
    @IBOutlet weak var goodsImg: UIImageView!
    // 名称
    @IBOutlet weak var goodsName: UILabel!
    // 原价
    @IBOutlet weak var oldPrice: UILabel!
    // 券后价
    @IBOutlet weak var subPrice: UILabel!
    // 优惠券
    @IBOutlet weak var coupon: UILabel!
    // 返利
    @IBOutlet weak var refund: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    func setUI(_ info: TBGoods) {
        goodsImg.zm.setImage(urlStr: info.mainPic)
        goodsName.text = info.title
        coupon.text = info.couponPrice.zm.toString(keep: 2) + "元"
        oldPrice.text = "¥\(info.originalPrice.zm.toString(keep: 2))"
        refund.text = "\(info.actualPrice > 5 ? 5.0 : info.actualPrice)"
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        oldPrice.zm.addDeleteLine("#999999".zm.hex())
        
        let attrString = NSMutableAttributedString(string: subPrice.text!)
        attrString.addAttributes([.font: UIFont(name: "PingFangSC-Medium", size: 12)!], range: NSRange(location: 0, length: 7))
        subPrice.attributedText = attrString
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
